package com.explorati.design_pattern.structural.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * 利用工厂获取对象
 * 
 * @author explorati
 *
 */
public class EmployeeFactory {

	// 一个Map容器
	private static final Map<String, Employee> EMPLOYEE_MAP = new HashMap<String, Employee>();

	public static Employee getManager(String department) {
		// 一个部门又有一个部门经理，报告也是一个，下次无需在创建
		Manager manager = (Manager) EMPLOYEE_MAP.get(department);
		// 如果map中不存在，创建
		if (manager == null) {
			manager = new Manager(department);
			System.out.println("创建部门经理：" + department);
			String reportContent = department + "部门汇报，此次汇报的内容是。。。";
			manager.setReportContent(reportContent);
			System.out.println(" 创建报告：" + reportContent);
			EMPLOYEE_MAP.put(department, manager);

		}
		return manager;
	}
}
